// @Author miaoqing
// @Date 2024/10/21 10:48:00
// @Desc
package logic

import (
	"bufio"
	"core/component/function"
	"fmt"
	"os"
	"strings"
)

func StartInput() {
	reader := bufio.NewReader(os.Stdin)
	fmt.Println("请输入内容，按回车键提交，输入'exit'退出：")
	go func() {
		for {
			input, err := reader.ReadString('\n') // 读取一行输入，直到遇到换行符
			if err != nil {
				fmt.Println("读取输入时发生错误：", err)
				os.Exit(1)
			}
			input = strings.TrimSpace(input) // 去除输入的前后空格
			if input == "exit\n" || input == "exit" {
				fmt.Println("退出程序。")
				break
			}
			fmt.Printf("你输入了: %s\n", input)
			ar := function.SplitStringToFloatSlice(input, ",")
			robot := WorldGetMe().getRobotByID(1)
			if robot != nil {
				if ar[0] == 1 {
					robot.setGoalPoint(ar[1], ar[2], ar[3])
				} else {
					//robot.setCmdVel(ar[1], ar[2], ar[3])
				}
			}
		}
	}()
}
